<?php
	 include("backManager/Comment.php");
     if(isset($_GET["delId"])){//删除
       $delId=$_GET["delId"];
   	   $isSucc=Comment::delComtById($delId);
       if($isSucc){
       	  header("location:index.php?targetPhp=comment/comList.php&showMsg=删除评论成功！");
       }else{
       	   echo "alert('删除失败！')";
       }
   }

    $comList=Comment::getCommentList();
?>
<script>
	function addComt(){
		window.location("index.php?targetPhp=comment/addComt.php");
	}
	var K;
	KindEditor.ready(function(Ke) {
			K=Ke;
	});
	var editor;
	function ajaxGetComt(id){
	           $.ajax({
			           type: "POST",
			           url: "backManager/ajaxGetComt.php",
			           data: "comtId="+id,
			           success: function(msg){
			                 showDialog(msg,id);
			                 showEditor().focus();
			           }
	            });
	 }
	function showDialog(msg,upId){
		var dialog = K.dialog({
						width : 500,
						title : '修改评论',
						body : '<div style="margin:10px;"><textarea name="content" style="width:100%;height:200px;visibility:hidden;">'+msg+'</textarea></div>',
						closeBtn : {
							name : '关闭',
							click : function(e) {
								dialog.remove();
							}
						},
						yesBtn : {
							name : '确定',
							click : function(e) {
								var upcont=editor.html();
								ajaxUpContById(upId,upcont);
								dialog.remove();
							}
						},
						noBtn : {
							name : '取消',
							click : function(e) {
								dialog.remove();
							}
						}
					});
	   return dialog;
	}
	
	function showEditor(){
		editor = K.create('textarea[name="content"]', {
					resizeType : 1,
					allowPreviewEmoticons : false,
					allowImageUpload : false,
					items : [
						'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
					afterBlur:function(){this.sync();}
		});
		return editor;
	}
	
	function ajaxUpContById(id,cont){
		$.ajax({
			           type: "POST",
			           url: "backManager/ajaxUpComt.php",
			           data: "comtId="+id+"&upCont="+cont,
			           success: function(msg){
			           	     shMsg="更新评论失败！";
			           	     if(msg)
			           	        shMsg="更新评论成功！";
			                 window.location("index.php?targetPhp=comment/comList.php&showMsg="+shMsg);
			           }
	     });
	}
			
			
</script>
<div class="rightTop">
	<span>评论管理列表</span>
	<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
	<input type="button" onclick="addComt();" value=" 新增评论 "  />
	<span>
		<?php 
    	    if(isset($_GET['showMsg']))
    	    	echo $_GET['showMsg'];
    	?>
	</span>
</div><!--rightTop end-->
<table class="bodyInside">
	<tr class="tableTitle" width="90%">
	    <th width="6%">id</th>
		<th width="10%">评论者id</th>
		<th width="35%">评论内容</th>
		<th width="10%">被评论文章</th>
		<th width="8%">文章作者</th>
		<th width="8%">评论日期</th>
		<th width="8%">评论时间</th>
		<th width="15%">操作</th>
	</tr>
    <?php
      	foreach($comList as $keys=>$comt){ 
		     echo "<tr align='center'>";
		     echo "<td>".$comt->id."</td>";
	         echo "<td>".$comt->userid."</td>";
			 echo "<td>".$comt->content."</td>";
			 echo "<td>".$comt->title."</td>";
			 echo "<td>".$comt->author."</td>";
			 $dt=$comt->wrtdt;
			 echo "<td>".substr($dt, 0,4)."/".substr($dt, 4,2)."/".substr($dt, 6,2)."</td>";
			 $tm=$comt->wrttm;
			 echo "<td>".substr($tm, 0,2).":".substr($tm, 2,2)."</td>";
			 echo "<td><a class='edit' href='javascript:ajaxGetComt(".$comt->id.")'>修改</a>&nbsp;&nbsp;";
			 echo "<a href='?targetPhp=comment/comList.php&delId=".$comt->id."'>删除</a></td>";		
			 echo "</tr>";
	    }
    ?>
</table>


